package uploaddemo.demo.upload;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import uploaddemo.demo.server.OssUploadFile;
import uploaddemo.demo.server.UploadServer;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * ClassName:UploadController
 * Package:uploaddemo.demo.upload
 * Description: 描述信息
 *
 * @date:2022/4/24 20:05
 * @author:动力节点
 */
@Controller
public class OssUploadController {

    @Autowired
    private UploadServer uploadServer;
    @Autowired
    private OssUploadFile ossUploadFile;
    /**
     * 文件上传的具体实现
     * @param multipart
     * @param request
     * @return
     */
    @PostMapping("/upload/oss")
    @ResponseBody
    public Map<String,Object> uploadFile(@RequestParam("file") MultipartFile multipart, HttpServletRequest request){
        String dir = request.getParameter("dir");
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("url",ossUploadFile.uploadFile(multipart,dir));
        return map;
    }
}
